﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Erp.Runtime.Composition
{
    /// <summary>
    /// IPart的比较工具
    /// </summary>
    internal sealed class PartEqualityComparer : IEqualityComparer<IPart>
    {
        public static readonly PartEqualityComparer Default;

        static PartEqualityComparer()
        {
            Default = new PartEqualityComparer();
        }

        public bool Equals(IPart x, IPart y)
        {
            return (object.ReferenceEquals(x,y) ||
                    (!object.ReferenceEquals(x,null) && 
                     !object.ReferenceEquals(y,null) && 
                     (x.Name == y.Name)));
        }

        public int GetHashCode(IPart obj)
        {
            return obj.Name.GetHashCode();
        }
    }
}
